package com.cms.action;

import java.util.ArrayList;
import java.util.List;

import com.action.DefaultAction;
import com.cms.manager.TypeManager;
import com.cms.model.Type;

public class TypeAction extends DefaultAction {

	public String show()
	{
		if(msg.equals("update"))
		{
			type = service.getById(type.getId());
		}
		return SUCCESS;
	}
	
	public String save()
	{
		if(msg.equals("insert"))
		{
			if(service.insert(type))
			{
				msg="类别管理：添加类别成功！！";
			}
			else
			{
				msg="类别管理：对不起，添加类别可能存在问题，请稍候重试一下！！";
			}
		}
		else if(msg.equals("update"))
		{
			if(service.update(type))
			{
				msg="类别管理：更新类别成功！！";
			}
			else
			{
				msg="类别管理：对不起，更新类别可能存在问题，请稍候重试一下！！";
			}
		}
		else if(msg.equals("del"))
		{
			if(service.delete(type))
			{
				msg="类别管理：删除类别成功！！";
			}
			else
			{
				msg="类别管理：对不起，删除类别可能存在问题，请稍候重试一下！！";
			}
		}
		return SUCCESS;
	}
	
	public String list()
	{
		tlist = service.getAll();
		return SUCCESS;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5229383555602791805L;

	private TypeManager service = TypeManager.getInstance();
	private Type type = new Type();
	private List<Type> tlist = new ArrayList<Type>();
	private String msg="";
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public List<Type> getTlist() {
		return tlist;
	}
	public void setTlist(List<Type> tlist) {
		this.tlist = tlist;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
